package com.ruoyi.web.controller.suggestion;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.suggestion.domain.CommunityCategory;
import com.ruoyi.suggestion.service.ICommunityCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 建议分类Controller
 * 
 * @author xianyu
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/suggestion/category")
public class CommunityCategoryController extends BaseController
{
    @Autowired
    private ICommunityCategoryService communityCategoryService;

    /**
     * 查询建议分类列表
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityCategory communityCategory)
    {
        startPage();
        List<CommunityCategory> list = communityCategoryService.selectCommunityCategoryList(communityCategory);
        return getDataTable(list);
    }

    /**
     * 导出建议分类列表
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:export')")
    @Log(title = "建议分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityCategory communityCategory)
    {
        List<CommunityCategory> list = communityCategoryService.selectCommunityCategoryList(communityCategory);
        ExcelUtil<CommunityCategory> util = new ExcelUtil<CommunityCategory>(CommunityCategory.class);
        util.exportExcel(response, list, "建议分类数据");
    }

    /**
     * 获取建议分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityCategoryService.selectCommunityCategoryById(id));
    }

    /**
     * 新增建议分类
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:add')")
    @Log(title = "建议分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityCategory communityCategory)
    {
        return toAjax(communityCategoryService.insertCommunityCategory(communityCategory));
    }

    /**
     * 修改建议分类
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:edit')")
    @Log(title = "建议分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityCategory communityCategory)
    {
        return toAjax(communityCategoryService.updateCommunityCategory(communityCategory));
    }

    /**
     * 删除建议分类
     */
    @PreAuthorize("@ss.hasPermi('suggestion:category:remove')")
    @Log(title = "建议分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityCategoryService.deleteCommunityCategoryByIds(ids));
    }
}
